#include "Rectangulo.h"
#include <Box2D/Box2D.h>

Rectangulo::Rectangulo(float width, float high)
{
	this->width = width;
	this->high = high;
	this->setScale(sqrt(width*width/4.0f + high*high/4.0f));
	this->initialRadAngle = (atan2f(this->getWidth(), this->getHigh()));

	stringstream ssUtil;
}

float Rectangulo::getRadRotation(float rotationAngle) {
	return float((rotationAngle / 180.0)*Constants::PI);
}

// 0 <= v <= 3
float Rectangulo::calculateVertexX(int v) {
	//1ER CUAD
	if (v == 0)
		return getScale()*sin(initialRadAngle - this->getRadRotation(this->getRotation()));
	//2DO CUAD
	if (v == 1)
		return getScale()*sin(initialRadAngle + this->getRadRotation(this->getRotation()));
	//3ER CUAD
	if (v == 2)
		return -getScale()*sin(initialRadAngle - this->getRadRotation(this->getRotation()));
	//4TO CUAD
	if (v == 3)
		return -getScale()*sin(initialRadAngle + this->getRadRotation(this->getRotation()));
}

float Rectangulo::calculateVertexY(int v) {
	//1ER CUAD
	if (v == 0)
		return getScale()*cos(initialRadAngle - this->getRadRotation(this->getRotation()));
	//2DO CUAD
	if (v == 1)
		return -getScale()*cos(initialRadAngle + this->getRadRotation(this->getRotation()));
	//3ER CUAD
	if (v == 2)
		return -getScale()*cos(initialRadAngle - this->getRadRotation(this->getRotation()));
	//4TO CUAD
	if (v == 3)
		return getScale()*cos(initialRadAngle + this->getRadRotation(this->getRotation()));
}

float Rectangulo::calculateVertexOneX() {
	return calculateVertexX(0);
}

float Rectangulo::calculateVertexOneY() {
	return calculateVertexY(0);
}

float Rectangulo::calculateVertexTwoX() {
	return calculateVertexX(1);
}

float Rectangulo::calculateVertexTwoY() {
	return calculateVertexY(1);
}

float Rectangulo::calculateVertexThreeX() {
	return calculateVertexX(2);
}

float Rectangulo::calculateVertexThreeY() {
	return calculateVertexY(2);
}

float Rectangulo::calculateVertexFourX() {
	return calculateVertexX(3);
}

float Rectangulo::calculateVertexFourY() {
	return calculateVertexY(3);
}

void Rectangulo::initPoints() {
	Position* p1 = new Position(calculateVertexOneX(), calculateVertexOneY());
	Position* p2 = new Position(calculateVertexTwoX(), calculateVertexTwoY());
	Position* p3 = new Position(calculateVertexThreeX(), calculateVertexThreeY());
	Position* p4 = new Position(calculateVertexFourX(), calculateVertexFourY());
	
	points.clear();

	points.push_back(p1);
	points.push_back(p2);
	points.push_back(p3);
	points.push_back(p4);
}

void Rectangulo::setSize(float width, float high){
	this->width = width;
	this->high = high;
}

float Rectangulo::getWidth(){
	return this->width;
}
float Rectangulo::getHigh(){
	return this->high;
}


Figure* Rectangulo::clone() {
	Rectangulo* figure = new Rectangulo(this->getWidth(), this->getHigh());

	figure->setScale(this->scale);
	figure->set_position(this->getX_position(), this->getY_position());
	figure->setColor(this->getColor());
	figure->setRGBColor(this->getRedComponent(), this->getGreenComponent(), this->getBlueComponent());
	figure->setRotation(0);
	figure->setInitialRotation(this->getRotation());
	figure->setStaticFlag(this->is_static());
	figure->setMass(this->getMass());
	

	return figure;
}

Rectangulo::~Rectangulo(void)
{
}
